package com.gitee.feizns.itrip.personal.biz.service.impl;

import com.gitee.feizns.itrip.personal.biz.entity.ao.ForAcceptSearchHotelRoomByHotel;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewGetImg;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewHotelLable;
import com.gitee.feizns.itrip.personal.biz.entity.vo.ForViewSearchHotelRoomByHotel;
import com.gitee.feizns.itrip.personal.biz.mapper.BizHotelRoomMapper;
import com.gitee.feizns.itrip.personal.biz.mapper.BizImageMapper;
import com.gitee.feizns.itrip.personal.biz.mapper.BizLabelDicMapper;
import com.gitee.feizns.itrip.personal.biz.service.HotelOrderService;
import com.gitee.feizns.itrip.personal.biz.service.HotelRoomService;
import com.gitee.feizns.itrip.personal.mapper.ImageMapper;
import com.gitee.feizns.itrip.personal.mapper.LabelDicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author feizns
 * @since 2019/1/8 0008
 */
@Service
public class HotelRoomServiceImpl implements HotelRoomService {

    /**
     *
     */
    public static final int LOWER_LIMIT_OF_THE_NUMBER_OF_ROOMS = 1;

    @Autowired
    private BizImageMapper bizImageMapper;

    @Autowired
    private BizLabelDicMapper bizLabelDicMapper;

    @Autowired
    private BizHotelRoomMapper bizHotelRoomMapper;

    @Autowired
    private HotelOrderService hotelOrderService;

    @Override
    public List<ForViewGetImg> getImg(Integer roomId) {
        return bizImageMapper.getImg(ImageMapper.IMG_ROOM_TYPE, roomId);
    }

    @Override
    public List<ForViewHotelLable> queryHotelRoomBed() {
        return bizLabelDicMapper.selectByParentId(LabelDicMapper.BED_PARENT_ID);
    }

    @Override
    public List<ForViewSearchHotelRoomByHotel> queryHotelRoomByHotel(ForAcceptSearchHotelRoomByHotel search) {
        List<Long> ids = bizHotelRoomMapper.queryHotelRoomByHotel(search);
        Long[] temp = null;
        return (temp = ids.stream().filter(id -> id != null
                && hotelOrderService.getStore(id, search.getStartDate(), search.getEndDate()) >= LOWER_LIMIT_OF_THE_NUMBER_OF_ROOMS)
                .toArray(Long[]::new)) != null && temp.length > 0 ? bizHotelRoomMapper.getRooms(temp) : null;
    }

}
